//
//  LZGroupListViewTableViewCell.m
//  laziz_Consumer
//
//  Created by xbn_iMac on 2016/11/18.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZGroupListViewTableViewCell.h"
#import "UIView+Rotation.h"
#import "LZGroupListModel.h"
#import "LZCustomerUserModel.h"
#import "UIImageView+WebCache.h"

@interface LZGroupListViewTableViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *bgImageView;
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UILabel *labTitle;
@property (weak, nonatomic) IBOutlet UILabel *labContent;
@property (weak, nonatomic) IBOutlet UIImageView *arrowImageView;
@property (weak, nonatomic) IBOutlet UILabel *labNowPersonNum;
@property (weak, nonatomic) IBOutlet UILabel *labDecollator;
@property (weak, nonatomic) IBOutlet UILabel *labTotlePersonNum;
@property (weak, nonatomic) IBOutlet UIButton *btnJoin;

@end

@implementation LZGroupListViewTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = [UIColor clearColor];
    
    [self.arrowImageView setLanguageRotaion];
    
    self.bgImageView.layer.cornerRadius = 4;
    self.headImageView.layer.masksToBounds = YES;
    self.headImageView.layer.cornerRadius = CGRectGetWidth(self.headImageView.bounds)/2.0;
    self.btnJoin.layer.borderWidth = 0.5;
    self.btnJoin.layer.borderColor = UIColorFromRGB(0xFF7A21, 1).CGColor;
    self.btnJoin.layer.cornerRadius = CGRectGetHeight(self.btnJoin.bounds)/2.0;
    [self.btnJoin setTitle:LZLocalizedString(@"group_join_big", nil) forState:UIControlStateNormal];
    
    // ******************** 添加阴影效果 ********************
    [self initLayerShadow];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    self.bgImageView.backgroundColor = highlighted ? UIColorFromRGB(0xdedede, 1) :  [UIColor whiteColor];
}

- (void)initLayerShadow {
    // 加阴影效果
    self.bgImageView.layer.masksToBounds = NO;
    // 阴影颜色
    self.bgImageView.layer.shadowColor = [UIColor blackColor].CGColor;
    //设置阴影的高度
    self.bgImageView.layer.shadowOffset = CGSizeMake(2, 2.5);
    //设置透明度
    self.bgImageView.layer.shadowOpacity = 0.05;
    //阴影半径，默认3
    self.bgImageView.layer.shadowRadius = 2;
}

- (IBAction)btnJoinClickAction:(UIButton*)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickJoinButtonAction:andIndexPath:)]) {
        [self.delegate clickJoinButtonAction:self.model andIndexPath:self.indexPath];
    }
}

- (void)setModel:(LZGroupListModel *)model {
    _model = model;
    
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",APIBaseImageUrl,model.customerUser.userPhoto]] placeholderImage:[UIImage imageNamed:@"lz_user_placehoiderImage"]];    // 开团人头像 
    self.labTitle.text = model.customerUser.nickname; // 开团人用户名
    self.labContent.text = model.groupName; // 开团名称
    self.labNowPersonNum.text = [NSString stringWithFormat:@"%ld",model.peopleCount];   // 当前参团人数
    self.labTotlePersonNum.text = [NSString stringWithFormat:@"%ld",model.grouponCount];    //  团购要去人数
    
    if ([LZLanguageManager shareInstance].getLanguageType == LanguageType_Ar) {
        self.labDecollator.text = @"\\";
    }
    else {
        self.labDecollator.text = @"/";
    }
}

@end
